package main

import (
	"context"
	"flag"
	"fmt"
	"gitee.com/gbat/rpcxDemo/example"
	"github.com/smallnest/rpcx/client"

	etcd_client "github.com/rpcxio/rpcx-etcd/client"
)

var (
	addr     = flag.String("addr", "localhost:6669", "server address")
	etcdAddr = flag.String("etcdAddr", "localhost:2379", "etcd address")
	basePath = flag.String("base", "/rpcx_test", "prefix path")
)

func main() {
	flag.Parse()

	d, err := etcd_client.NewEtcdV3Discovery(*basePath, "Arith", []string{*etcdAddr}, nil)
	if err != nil {
		fmt.Println(err)
	}

	xclient := client.NewXClient("Arith", client.Failtry, client.RandomSelect, d, client.DefaultOption)
	defer xclient.Close()

	args := &example.Args{
		A: 10,
		B: 20,
	}
	for i := 0; i < 10; i++ {
		reply := &example.Reply{}
		err := xclient.Call(context.Background(), "Mul", args, reply)
		if err != nil {
			fmt.Printf("failed to call: %v", err)
		}

		fmt.Printf("%d * %d = %d \n", args.A, args.B, reply.C)
	}
}
